package com.zzgele.qmzb.api.web;

import com.alibaba.boot.dubbo.annotation.DubboConsumer;
import com.github.pagehelper.PageInfo;
import com.zzgele.qmzb.api.core.Result;
import com.zzgele.qmzb.api.core.ResultGenerator;
import com.zzgele.qmzb.api.model.Help;
import com.zzgele.qmzb.api.service.HelpService;
import com.zzgele.qmzb.api.utils.PageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
* Created by Martin on 2017/07/13.
*/
@RestController
@RequestMapping("/help")
public class HelpController {
    private final Logger logger = LoggerFactory.getLogger(HelpController.class);
    @DubboConsumer
    private HelpService helpService;

    @PostMapping("/hot_list")
    public Result hot_list(Integer page_size) {
        PageUtil.startPage(1, page_size);
        Condition condition = new Condition(Help.class);
        condition.createCriteria().andCondition("is_hot=1" );
        condition.setOrderByClause("id ASC");
        List<Help> helpList = helpService.findByCondition(condition);

        return ResultGenerator.genSuccessResult(helpList);
    }

    @PostMapping("/type_list")
    public Result type_list(Integer type_id, Integer page, Integer page_size) {
        PageUtil.startPage(page, page_size);
        Condition condition = new Condition(Help.class);
        condition.createCriteria().andCondition("type_id="+type_id );
        condition.setOrderByClause("id ASC");
        List<Help> helpList = helpService.findByCondition(condition);
        HashMap helpListHashMap = PageUtil.getPageInfoHashMap(new PageInfo(helpList));
        return ResultGenerator.genSuccessResult(helpListHashMap);
    }
}
